import {String} from "core-js"

export default {
    name: "UserNav",
    data() {
        return {
            activeIndex: "userHome",
            avatarUrl: require("../../assets/test02.jpg"),
            menus: [],
            userInfo:{},
        }
    },
    created() {
        this.$store
        .dispatch("user/getUserInfo")
        .then(response => {
            this.userInfo = JSON.parse(response.result)
        })

        this.activeIndex = this.$route.name

        this.menus = [
            {
                index: "userHome",
                icon: 'el-icon-house',
                label: '首页'
            }, {
                index: "userOrder",
                icon: 'el-icon-tickets',
                label: '我的订单'
            }, {
                index: "userInvoice",
                icon: 'el-icon-bank-card',
                label: '我的发票'
            }, {
                index: "userCollect",
                icon: 'el-icon-first-aid-kit',
                label: '我的收藏'
            }, {
                index: "/cart",
                icon: 'el-icon-shopping-cart-2',
                label: '我的购物车'
            },
        ]
    },


    methods: {
        errorHandler() {
            return true
        },
        handleSelect(key, keyPath) {
            console.log(key)
            console.log(keyPath)
        },
        //切换菜单
        changeUserCenterMenu(index) {
            this.activeIndex = index
            this.$emit('userMenuChange', {menuIndex: index})
        },
    },
    mounted() {
        if (this.$route.query.curMenuIndex) {
            this.changeUserCenterMenu(this.$route.query.curMenuIndex)

        }
    }
}
